<?php
class newsControl extends Control{
    function index(){
		$id=$_GET['id'];
		$db = k("newsview");
		$db->inc("click","id=$id",1);
		$row = $db->where("id=$id")->field("id,title,username,addtime,click,body,keywords,thumb")->all();
		$row[0]["addtime"]=date("Y-m-d",$row[0]["addtime"]);
		$row[0]["thumburl"]=__ROOT__.'/'.$row[0]["thumb"];
		$row[0]["thumburl"]="<img  src='".$row[0]["thumburl"]."'/>";
		
		
		
		$db = K("commentview");
        $comment = $db->where("nid=$id","stat=1")->field("cid,title,nid,rebody,pid,retime,comment.uid,good,bad,username")->all();
        $comment = arr::channel($comment,"cid","pid",0,2,"&nbsp;&nbsp;&nbsp;&nbsp;");
		//p($comment);
        $this->assign("comment",$comment);
		
		
		
		/* $db=K("commentview");
		$reply=$db->join("user")->where("nid=$id","stat=1")->all();
		p($reply);
		$this->assign("reply",$reply); */
		$this->assign("row",$row);
		$this->display();
		//$this->display("add_replay_show");
    }
    
    function comment(){
		$id=$_GET['id'];
		
		
		$this->display("index");
	
	}
	function add_replay_show(){
		$id=$_GET['id'];
		$this->assign("id",$id);
		//p($_GET['id']);
		$this->display();
	
	
	}
	 function add(){
		$data = $_POST;
		
		$data['uid']=$_SESSION['uid'];
		
		$data['retime']=time();
		//p($data);exit;
		$db= M('comment');
        if($db->add($data)){
            $this->success("回复成功");
        }else{
            $this->error("回复失败");
        }
	 }
	 
    function add_reply(){
        $data = $_POST;
       // p($data);exit;
        $data['retime']=time();
        $data['uid']=$_SESSION['uid'];
        $id = $_POST['nid'];
        $db= M('comment');
        if($db->add($data)){
                $sql  = " update hd_news set replycount=replycount+1 where id='$id' ";
                $db->exe($sql);
                $this->success("回复成功",__APP__.'/news/index/id/'.$id);
        }else{
                $this->error("回复失败");
        }
    }
	function good(){
		$cid=$_GET["cid"];
		$db=M("comment");
		if($cid){
		$sql  = " update hd_comment set good=good+1 where cid='$cid' ";
		$db->exe($sql);
		$this->success("顶帖成功");
		}else{
			$this->error("顶帖失败");
		}
	}
	function bad(){
		$cid=$_GET["cid"];
		$db=M("comment");
		if($cid){
		$sql  = " update hd_comment set bad=bad+1 where cid='$cid' ";
		$db->exe($sql);
		$this->success("踩帖成功");
		}else{
			$this->error("踩帖失败");
		}
	}
	function add_rrrrr(){
		$uid=$_SESSION["uid"];
		$_POST["uid"]=$_SESSION["uid"];
		$_POST["rrtime"]=time();
		//p($_POST);exit;
		$db=M("rrrrr");
		if ($db->add()) {
            $this->success("回复评论成功!");
        } else {
            $this->error("回复评论失败");
        }
		
	}
	 function show_rrrrr(){
		$cid=$_GET["cid"];
		//p($cid);
		$db=M("rrrrr");
		$row=$db->where("cid=$cid")->all();
		$this->assign("row",$row);
		$this->display();
		
	
	
	} 
	/* function bad(){
		$cid=$_GET["cid"]；
		$this->display();
	} */
}